<?php if(!AJAX){ ?>
<?php

	$result = mysql_query("SELECT * FROM `197_sidebar` WHERE `position` = 0");
	$leftbar = array();
	while($row = mysql_fetch_assoc($result)){
		array_push($leftbar, $row);
	}

?>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="Generator" content="197website; Version: <?php echo APP_VERSION; ?>" />
		<meta name="Keywords" content="<?php echo $set['site_keywords']; ?>" />
		<meta name="Description" content="<?php echo $set['site_description']; ?>" />
		<title><?php echo $set['site_name']; ?></title>
		<link rel="stylesheet" href="style.css" />
		<link rel="stylesheet" href="jquery/css/custom-theme/jquery-ui-1.8.4.custom.css" />
		<link rel="stylesheet" href="jquery/css/tabs-flowplayer-v2.css" />
		<script type="text/javascript" src="jsSettings.php"></script>
		<script type="text/javascript" src="jquery/js/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="jquery/js/jquery-ui-1.8.4.custom.min.js"></script>
		<script type="text/javascript" src="jquery/tiny_mce/jquery.tinymce.js"></script>
		<script type="text/javascript" src="jquery/js/jquery.tools.min.js"></script>
		<script type="text/javascript" defer="defer">
			$(function(){
				$("#hw-datepicker-dialog").dialog({
					modal: true,
					draggable: false,
					resizable: false,
					autoOpen: false,
					title: "日期選擇",
					width: 315,
					height: 280
				});
				$("#hw-datepicker").datepicker({
					dateFormat: "yy-mm-dd",
					onSelect: function(d, i){
						location.replace("homeworks.php?date=" + d);
					}
				});
				$("#logout-result-dialog").dialog({
					modal: true,
					draggable: false,
					resizable: false,
					autoOpen: false,
					title: "訊息",
					width: 315,
					height: 280
				});

			});
			function today(){
				var d = new Date();
				return (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate());
			}
			function doLogin(){
				$("#login-result").append("<img src='images/ajax-loader.gif' />");
				$.post("login.php?ajax=true", { username: $("#username").val(), password: $("#password").val() }, function(r){
					$("#login-result").html(r);
					//alert(r);
				});
			}
			function doLogout(){
				$("#logout-result").append("<img src='images/ajax-loader.gif' />");
				$("#logout-result").load("logout.php?ajax=true");
			}

		</script>
	</head>
	<body>
		<div id="page">
			<div id="header">
				<a href="index.php"><img src="<?php echo $set['site_logo']; ?>" alt="197班網" id="logo" /></a>
				<img src="http://www.hs.ntnu.edu.tw/spirit/markflag/flag_n.gif" />
				<div id="navigation">
					<a href="index.php">首頁</a>｜<a href="#" onclick="location.replace('homeworks.php?date=' + today());">今日聯絡簿</a>
				</div>
			</div>
			<div id="hw-datepicker-dialog">
				<div id="hw-datepicker"></div>
			</div>
			<div id="leftbar">
				<div class="sidebar-item" id="login-form">
					<h1>〉狀態</h1>
					<?php if(isset($_SESSION['username'])){ ?>
						<p>您已用了「<?php echo $_SESSION['username']; ?>」的身分登入。</p>
						<ul>
							<li><a href="logout.php" onclick="doLogout(); return false;">登出</a></li>
							<?php if($_SESSION['type'] == 2){ ?>
								<li><a href="admin/index.php">控制台</a></li>
							<?php } ?>
						</ul>
						<div id="logout-result">
						</div>
					<?php } else { ?>
						<p>您尚未登入。</p>
						<form id="login-form" action="login.php" method="POST" onsubmit="doLogin(); return false;" onclick="">
							<p><label>帳號：<input type="text" id="username" name="username" /></label></p>
							<p><label>密碼：<input type="password" id="password" name="password" /></label></p>
							<p><input type="submit" value="登入" />｜<input type="button" onclick="location.replace('register.php'); return false;" value="註冊" /></p>
							<div id="login-result"></div>
						</form>
					<?php } ?>
				</div>
				<div class="sidebar-item">
					<h1>〉老師區</h1>
					<ul>
						<li><a href="teacherData.php?teacher_id=1">生物老師區</a></li>
						<li><a href="teacherData.php?teacher_id=2">國文老師區</a></li>
					</ul>
				</div>
				<div class="sidebar-item">
					<h1>〉活動紀錄</h1>
					<ul>
						<li><a href="albumList.php"><strong>相簿（新！）</strong></a></li>
						<li><a href="articleList.php">作文平台</a></li>
						<li><a href="linkFind.php">好站連結</a></li>
						<li><a href="calendar.php">行事曆</a></li>
					</ul>
				</div>
				<?php foreach($leftbar as $row){ ?>
					<div class="sidebar-item">
						<h1>〉<?php echo $row['title']; ?></h1>
						<?php echo $row['content']; ?>
					</div>
				<?php } ?>
			</div>
			<div id="main">
<?php } ?>